package com;

import com.utils.AESUtil;

public class AES {
    static public void main(String[] argv) {
        try {
            String value1 = AESUtil.Encrypt("20200720061245", "0000000000000000");
            System.out.println(value1);

//            byte[] a = new byte[]{
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00,
//                    0x00
//            };
//
//            String str = new String(a);
//            String value = AESUtil.Encrypt("20200720061245", str);
//            System.out.println(value);

            System.out.println(bytesToHex(value1.getBytes()));

            System.out.println(AESUtil.md5("0"));
            System.out.println(AESUtil.md5(new byte[]{0x00}));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static String string2HexString(String strPart) {
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < strPart.length(); i++) {
            int ch = (int) strPart.charAt(i);
            String strHex = Integer.toHexString(ch);
            hexString.append(strHex);
        }
        return hexString.toString();
    }

    /**
     * 字节转十六进制
     *
     * @param b 需要进行转换的byte字节
     * @return 转换后的Hex字符串
     */
    public static String byteToHex(byte b) {
        String hex = Integer.toHexString(b & 0xFF);
        if (hex.length() < 2) {
            hex = "0" + hex;
        }
        return hex;
    }


    /**
     * 字节数组转16进制
     *
     * @param bytes 需要转换的byte数组
     * @return 转换后的Hex字符串
     */
    public static String bytesToHex(byte[] bytes) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < bytes.length; i++) {
            String hex = Integer.toHexString(bytes[i] & 0xFF);
            if (hex.length() < 2) {
                sb.append(0);
            }
            sb.append(hex);
        }
        return sb.toString();

    }
}
